
<style type="text/css">
    #status{
        background-color: #A4D29D;
        border-bottom: 1px dashed #55a34a;
        border-top: 1px dashed #55a34a;
        text-align: center;
        height: 18px;
        padding-top: 5px;
        margin-bottom: 10px;
        color: #000;
    }

    .result-consulta{
        font-size: 15px;
    }

    .result-consulta div{
        margin-bottom: 5px;
    }

    .txt-result{
        float: left;
        width: 80px;
    }

    .pagamento{
        width: 300px;
    }

    #status{
        background-color: #FFA8A8;
        border-bottom: 1px dashed #55a34a;
        border-top: 1px dashed #55a34a;
        text-align: center;
        height: 18px;
        padding-top: 5px;
        margin-bottom: 10px;
        color: #000;
    }

    td{
        cursor: pointer;
    }

</style>

<div id="content">
<div id="main">

    <?php
            $elementMessages = $this->form->getMessages();
            if (sizeof($elementMessages) > 0)
            {
                echo '<div class=error>';
                foreach ($elementMessages as $element)
                {
                    foreach ($element as $message)
                    {

                        echo $message.'<br >';
                    }
                }
                echo '</div>';
            }
        ?>


            <h2><a href="#"><?=$this->breadcump1?></a> &raquo; <a href="#" class="active"><?=$this->breadcump2?></a></h2>            

                    ﻿<?=$this->form;?>                


            <?              
              if(isset($this->total)):
                      if($this->total <> 0):

            ?>

                <fieldset class="result-consulta">
                <? if(isset($this->titudep)) : ?>
                    <div><span class="txt-result">Nome: </span><? echo $this->titudep->nome?></div>
                    <div><span class="txt-result">Tipo: </span><b><? echo ($this->titudep->tipo == 'T') ? 'Titular' : 'Dependente';?></b></div>
                    <div><span class="txt-result">CPF: </span><? echo $this->titudep->cpf?></div>
                    <div><span class="txt-result">Contrato: </span><? echo $this->titudep->contrato?></div>
                    <br >

                <? endif; ?>
                    <table class="pagamento" style="width: 300px; margin: auto">
                        <thead>
                            <th>Mes</th>
                            <th>Valor</th>
                        </thead>
                        <tbody>
                <?

                   $pagamento = $this->titudep->findDependentRowSet('Application_Model_DbTable_Pagamento');

                   $total = 0;
                   foreach ($pagamento as $pagamentoItens) {
                ?>
                          <tr style="height: 4px">
                            <td><?=$pagamentoItens->mes_referencia?></td>
                            <td>
                                <?
                                  $formatted = number_format($pagamentoItens->valor , 2, ',', '.');
                                 //sprintf("%01,2f", $pagamentoItens->valor);
                                  echo $formatted;
                                ?></td>
                         </tr>
                <?
                    $total += $pagamentoItens->valor;
                  }
                ?>
                         <tr>
                             <td style="font-weight: bold; color: red">Total</td>
                             <td style="font-weight: bold; color: red"><?=number_format($total , 2, ',', '.');?></td>
                         </tr>
                        </tbody>
                    </table>
                    <br >
                    <fieldset style="font-size: 11px; background-color: #FFFFBF; width: 400px; margin: auto ">
                        <h4 style="text-align: center; margin-bottom: 20px">Dependentes</h4>
                <?

                    $titudep = new Application_Model_DbTable_TituDep();
                    $select = $titudep->select()->where('contrato = ' . $this->titudep->contrato . ' and id <> ' . $this->titudep->id);
                    $titudepRow = $titudep->fetchAll($select);

                    foreach ($titudepRow as $tituDepItens)
                    {
               ?>
                        <div><span class="txt-result">Nome: </span><? echo $tituDepItens->nome?></div>
                        <div><span class="txt-result">Tipo: </span><b><? echo ($tituDepItens->tipo == 'T') ? 'Titular' : 'Dependente';?></b></div>
                        <div><span class="txt-result">CPF: </span><? echo $tituDepItens->cpf?></div>
                        <div><span class="txt-result">Contrato: </span><? echo $tituDepItens->contrato?></div>
                        <br >

                        <table class="pagamento" style="width: 200px; margin: auto">
                        <thead>
                            <th>Mes</th>
                            <th>Valor</th>
                        </thead>
                        <tbody>

               <?

                   $pagamento = $tituDepItens->findDependentRowSet('Application_Model_DbTable_Pagamento');

                   $total = 0;
                   foreach ($pagamento as $pagamentoItens) {
               ?>
                         <tr>
                            <td><?=$pagamentoItens->mes_referencia?></td>
                            <td><?=$pagamentoItens->valor?></td>
                         </tr>
               <?
                    $total += $pagamentoItens->valor;
                  }
               ?>
                         <tr>
                             <td style="font-weight: bold; color: red">Total</td>
                             <td style="font-weight: bold; color: red"><?=$total?></td>
                         </tr>
                        </tbody>
                    </table>
                    <br >

                    <div style="border-bottom: 1px solid #9B9B9B; margin-bottom: 25px; margin-top: 20px;"></div>

               <?
                    }
               ?>
                  </fieldset>



                </fieldset>

            <?  else:
            ?>
                 <div id="status">CPF não localizado!</div>
            <?
                endif;                                                  
              endif;
            ?>

                
            <?
            if(isset($this->paginator)){
               echo $this->paginationControl( $this->paginator, 'Sliding', 'ir/pagination.phtml' );
            ?>

        
          <table class="fullwidth" cellpadding="0" cellspacing="0" border="0">
             <thead>
                 <td>Contrato</td>
                 <td>CPF</td>
                 <td>Nome</td>
             </thead>
            <?
            foreach( $this->paginator as $row )
            {
            ?>
                 <tr onclick="document.location = '<?= $this->url(array('cpf' => $row->cpf)); ?>'">
                     <td><?=$row->contrato?></td>
                     <td><?=$row->cpf?></td>
                     <td><? echo substr($row->nome, 0,50);?></td>                     
                 </tr>

            <?
            }
            ?>
         </table>        
         <?
            echo $this->paginationControl( $this->paginator, 'Sliding', 'ir/pagination.phtml' );
         }
         ?>         
</div>
<div class="clear"></div>
</div>



<div id="sidebar">
    <h2>Navegação</h2>
    <ul>
        <li><a href="<?=$this->url(array('controller' => 'ir', 'action' => 'index'),'',true)?>">Histórico</a></li>
        <li><a href="<?=$this->url(array('controller' => 'ir', 'action' => 'cadastro'),'',true)?>">Upload Titul/Depend</a></li>
        <li><a href="<?=$this->url(array('controller' => 'ir', 'action' => 'consulta'),'',true)?>">Consulta</a></li>
    </ul>
</div>
